<template>
 <view class="goods">
          <view class="goods-item-img">
         <radio :checked="goods.goods_state" color="#C00000" v-if="showRadio" @click="radioClick"></radio>
            <image :src="goods.goods_big_logo || defaultImg"></image>
            </view>
          <view class="goods-item-text">
            <text class="goods-item-text-title">{{goods.goods_name}}</text><br/>
           <view class="goods-info-box">
             <text class="goods-item-text-price">￥{{goods.goods_price | tofixed}}</text>
              <uni-number-box :min="1" :value="goods.goods_count" v-if="showNum" @change="numChanger"></uni-number-box>
           </view>
            </view>
      </view>
</template>

<script>
  export default {
    name:"my-goods",
    props:{
      goods:{
        type:Object,
        default:{}
      },
      showRadio:{
        type:Boolean,
        default:false
      },
      showNum:{
        type:Boolean,
        default:false
      }
    },
    data() {
      return {
        defaultImg: 'https://img3.doubanio.com/f/movie/8dd0c794499fe925ae2ae89ee30cd225750457b4/pics/movie/celebrity-default-medium.png'
      };
    },
    methods:{
      radioClick(){
        this.$emit('radio-change',{
          goods_id: this.goods.goods_id,
          goods_state:!this.goods.goods_state
        })
      },
      numChanger(val){
       this.$emit('num-change',{
         goods_id: this.goods.goods_id,
         goods_count: val-0
       })
      }
      
    },
    filters:{
      tofixed(num){
      return  Number(num).toFixed(2)
      }
    }
  }
</script>

<style lang="scss">
 .goods{
      display: flex;
      padding: 10px 5px;
      border-bottom: 1px solid #f0f0f0;
    .goods-item-img{
        margin-right: 5px;
        display:flex;
        justify-content: space-between;
        align-items: center;
        image{
           width: 100px;
           height: 100px;
           display: block;
        }
    }
    .goods-item-text{
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      .goods-item-text-title{
        font-size: 13px;
      }
      .goods-info-box{
        display: flex;
            align-items: center;
            justify-content: space-between;
            .goods-item-text-price{
               font-size: 16px;
                  color: #c00000;
            }
      }
    }
  }
</style>